package com.ruoyi.web.controller.deviceManager;

import com.cs.deviceManager.domain.DevTelemetryData;
import com.cs.deviceManager.service.IDevTelemetryDataService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备遥测数据Controller
 * 
 * @author system
 * @date 2025-08-01
 */
@Controller
@RequestMapping("/deviceManager/telemetry")
public class DevTelemetryDataController extends BaseController {
    private String prefix = "deviceManager/telemetry";

    @Resource
    private IDevTelemetryDataService devTelemetryDataService;

    @RequiresPermissions("deviceManager:telemetry:view")
    @GetMapping()
    public String telemetry() {
        return prefix + "/telemetry";
    }

    /**
     * 查询设备遥测数据列表
     */
    @RequiresPermissions("deviceManager:telemetry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DevTelemetryData devTelemetryData) {
        startPage();
        List<DevTelemetryData> list = devTelemetryDataService.selectDevTelemetryDataList(devTelemetryData);
        return getDataTable(list);
    }

    /**
     * 导出设备遥测数据列表
     */
    @RequiresPermissions("deviceManager:telemetry:export")
    @Log(title = "设备遥测数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DevTelemetryData devTelemetryData) {
        List<DevTelemetryData> list = devTelemetryDataService.selectDevTelemetryDataList(devTelemetryData);
        ExcelUtil<DevTelemetryData> util = new ExcelUtil<DevTelemetryData>(DevTelemetryData.class);
        return util.exportExcel(list, "设备遥测数据");
    }

    /**
     * 查看设备遥测数据详情
     */
    @RequiresPermissions("deviceManager:telemetry:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        DevTelemetryData devTelemetryData = devTelemetryDataService.selectDevTelemetryDataById(id);
        mmap.put("devTelemetryData", devTelemetryData);
        return prefix + "/detail";
    }

    /**
     * 删除设备遥测数据
     */
    @RequiresPermissions("deviceManager:telemetry:remove")
    @Log(title = "设备遥测数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long[] ids) {
        return toAjax(devTelemetryDataService.deleteDevTelemetryDataByIds(ids));
    }

    /**
     * 清空设备遥测数据
     */
    @RequiresPermissions("deviceManager:telemetry:clear")
    @Log(title = "设备遥测数据", businessType = BusinessType.CLEAN)
    @PostMapping("/clear")
    @ResponseBody
    public AjaxResult clear() {
        devTelemetryDataService.clearDevTelemetryData();
        return AjaxResult.success("清空成功");
    }
}